package com.ruoyi.material.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.material.domain.MaterialWeld;
import com.ruoyi.material.service.IMaterialWeldService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 焊材管理Controller
 * 
 * @author ruoyi
 * @date 2023-01-14
 */
@Controller
@RequestMapping("/material/weld")
public class MaterialWeldController extends BaseController
{
    private String prefix = "material/weld";

    @Autowired
    private IMaterialWeldService materialWeldService;

    @RequiresPermissions("material:weld:view")
    @GetMapping()
    public String weld()
    {
        return prefix + "/weld";
    }

    /**
     * 查询焊材管理列表
     */
    @RequiresPermissions("material:weld:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MaterialWeld materialWeld)
    {
        startPage();
        List<MaterialWeld> list = materialWeldService.selectMaterialWeldList(materialWeld);
        return getDataTable(list);
    }

    /**
     * 导出焊材管理列表
     */
    @RequiresPermissions("material:weld:export")
    @Log(title = "焊材管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MaterialWeld materialWeld)
    {
        List<MaterialWeld> list = materialWeldService.selectMaterialWeldList(materialWeld);
        ExcelUtil<MaterialWeld> util = new ExcelUtil<MaterialWeld>(MaterialWeld.class);
        return util.exportExcel(list, "焊材管理数据");
    }

    /**
     * 新增焊材管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存焊材管理
     */
    @RequiresPermissions("material:weld:add")
    @Log(title = "焊材管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MaterialWeld materialWeld)
    {
        return toAjax(materialWeldService.insertMaterialWeld(materialWeld));
    }

    /**
     * 修改焊材管理
     */
    @RequiresPermissions("material:weld:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MaterialWeld materialWeld = materialWeldService.selectMaterialWeldById(id);
        mmap.put("materialWeld", materialWeld);
        return prefix + "/edit";
    }

    /**
     * 修改保存焊材管理
     */
    @RequiresPermissions("material:weld:edit")
    @Log(title = "焊材管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MaterialWeld materialWeld)
    {
        return toAjax(materialWeldService.updateMaterialWeld(materialWeld));
    }

    /**
     * 删除焊材管理
     */
    @RequiresPermissions("material:weld:remove")
    @Log(title = "焊材管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(materialWeldService.deleteMaterialWeldByIds(ids));
    }
}
